package com.gm.wj.dao;

import com.gm.wj.entity.SysStudent;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface SysStudentDAO extends JpaRepository<SysStudent,Integer> {
    SysStudent findById(int id);

    // 多条件模糊查询
    @Query(value = "select * from sys_student  where  (?1 is null or enabled like ?1) and (?2 is null or stu_no like ?2) and (?3 is null or stu_name like ?3) and is_delete = 0",nativeQuery = true)
    List<SysStudent> find(String queryKey1, String queryKey2, String queryKey3);

    // jpa分页查询  多条件
    Page<SysStudent> findAll(Specification<SysStudent> sysStudentSpecification, Pageable pageable);

    // 首页数据统计
    @Query(value = "select count(*) from sys_student  where is_delete = 0",nativeQuery = true)
    int countByStudent();

    SysStudent findByUsername(String username);
}
